﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _formTools : System.Web.UI.Page
{
    
    public List<LIB.easyDoc> listDoc = new List<LIB.easyDoc>();
    protected void Page_Load(object sender, EventArgs e)
    {
        //string test = "a.aspx.cs";
        //string result = LIB.trans.getExt(test);
        //Response.Write(result);
        //Response.End();

        if (!IsPostBack)
        {

        }
    }

    protected void btnGenCode_Click(object sender, EventArgs e)
    {
        string cont = txtCont.Text;
        dealHtml(cont);
    }

    private void dealHtml(string cont)
    {
        string[] line = txtCont.Text.Trim().Replace(",", "，").Replace("\n", "").Split('\r');
        string res = "";

        string fldName = "";
        if (line.Length < 2)
        {
            res = "错误的格式";
        }
        else
        {
            fldName = line[0].Split('，')[0];
            string[] arrTitle = line[1].Trim().Split('，');
            string[] arrValue = line[1].Trim().Split('，');
            if (line.Length > 2)
            {
                arrValue = line[2].Trim().Split('，');
            }
            string htmlType = rdType.SelectedValue;
            string str_class = string.Format("class=\"{0}\"", txtClass.Text.Trim());
            var sb = new StringBuilder();
            switch (rdType.SelectedValue)
            {
                case "vue":
                    sb.Append("<textarea cols=100 rows=5>");
                    sb.AppendFormat("<select name=\"{0}\" id=\"sel_{0}\" v-model=\"formdata.{0}\" {1} >\r\n", fldName,str_class);
                    for (int i = 0; i < arrTitle.Length; i++)
                    {
                        sb.AppendFormat("   <option value=\"{1}\" >{0}</option>\r\n", arrTitle[i], arrValue[i]);
                    }
                    sb.AppendFormat("</select>\r\n");
                    sb.AppendFormat("\r\n\r\n");
                    sb.Append("</textarea>");

                    sb.Append("<textarea cols=100 rows=5>");
                    for (int i = 0; i < arrTitle.Length; i++)
                    {
                        sb.AppendFormat("<input type=\"radio\"  name=\"{0}\" value=\"{2}\" v-model=\"formdata.{0}\" {3} />{1}\r\n", fldName, arrTitle[i], arrValue[i],str_class);
                    }
                    sb.AppendFormat("\r\n\r\n");
                    sb.Append("</textarea>");

                    sb.Append("<textarea cols=100 rows=5>");

                    for (int i = 0; i < arrTitle.Length; i++)
                    {
                        sb.AppendFormat("<input type=\"checkbox\"  name=\"{0}\" value=\"{2}\" v-model=\"formdata.{0}\" {3} />{1}\r\n", fldName, arrTitle[i], arrValue[i],str_class);
                    }
                    sb.Append("</textarea>");
                    break;
                 default:
                    sb.Append("<textarea cols=100 rows=5>");
                    sb.AppendFormat("<select name=\"{0}\" id=\"sel_{0}\" {1} >\r\n", fldName, str_class);
                    for (int i = 0; i < arrTitle.Length; i++)
                    {
                        sb.AppendFormat("   <option value=\"{1}\" >{0}</option>\r\n", arrTitle[i], arrValue[i]);
                    }
                    sb.AppendFormat("</select>\r\n");
                    sb.AppendFormat("\r\n\r\n");
                    sb.Append("</textarea>");

                    sb.Append("<textarea cols=100 rows=5>");
                    for (int i = 0; i < arrTitle.Length; i++)
                    {
                        sb.AppendFormat("<input type=\"radio\"  name=\"{0}\" value=\"{2}\"  {3} />{1}\r\n", fldName, arrTitle[i], arrValue[i], str_class);
                    }
                    sb.AppendFormat("\r\n\r\n");
                    sb.Append("</textarea>");

                    sb.Append("<textarea cols=100 rows=5>");

                    for (int i = 0; i < arrTitle.Length; i++)
                    {
                        sb.AppendFormat("<input type=\"checkbox\"  name=\"{0}\" value=\"{2}\"  {3} />{1}\r\n", fldName, arrTitle[i], arrValue[i], str_class);
                    }
                    sb.Append("</textarea>");
                    break;
            }
         res = sb.ToString();
       }

        litReuslt.Text = res;
        //txtResult.Text = res;
    }


}